﻿using System;
using Netcare.Core;
using System.Threading;
using Netcare.Web.Host.Linux;
using System.IO;
using Netcare.Web.Host.NT;

namespace Netcare.Web.Host.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            App.InitializeAppDomainAndLogger();

            IWebHost host = null;

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                host = AspHost.Create(55505, "/", Directory.GetCurrentDirectory());
            }
            else if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                host = XspHost.Create(55505, "/", Directory.GetCurrentDirectory());
            }
            else
                throw new PlatformNotSupportedException();



            host.Start();
            Log.WriteInfo("Hosting {0} on {1}", 55505, Directory.GetCurrentDirectory());
            Log.WriteInfo("Press Q to stop me, press any other key to test!");

            string command = null;
            while ((command = System.Console.ReadLine()) != "q")
            {
                Log.WriteInfo("Try to invoke web method MySql.GetPeople()");
                using (localhost.MySql sc = new localhost.MySql())
                {
                    sc.Url = "http://localhost:55505/mysql.asmx";

                    var e = sc.GetPeople();
                    foreach (var p in e)
                    {
                        Log.WriteInfo(" Name={0}, Age={1}", p.Name, p.Age);
                    }
                }
            }

            host.Stop();
        }
    }
}
